1. Field of the Invention
The present invention relates generally to optimizing the performance of software code in a compiler, and more specifically, to a method of detecting potential violations of aliasing rules during the static analysis of source code.
2. Description of the Related Art
It is important that programmers follow existing type-based aliasing rules when coding programs. Type-based aliasing rules define alias sets for indirect memory accesses in a program. For example, there may be two pointers declared in a C/C++ program. Assume the first pointer, int* p1, is an integer pointer, and the second pointer, float* p2, is a float pointer. The type-based aliasing rules would prohibit p1 and p2 from pointing to the same memory location. Now assume the program contains a dereference of the integer pointer p1, and that p1 points to a float variable. This dereference would constitute a violation of the type-based aliasing rules for the program. During optimization, compilers may operate based on the assumption that the type-based aliasing rules were followed by the programmer. The compiler may, for example, interchange two store instruction assignment (*p1=3 and *p2=1.0f) by assuming that the two assignments cannot possibly modify the same memory location.
If the programmer violates the type-based aliasing rules, the compiler assumption may be invalid, and the program may be optimized incorrectly. Incorrectly optimized programs often produce unexpected results at runtime, and it may be extremely challenging to find the source of a failure, especially one that may be the result of a programmer error that causes an invalid compiler optimization.
In a related application Ser. No. 11/757,952, filed Jun. 4, 2007, and entitled “Method of Diagnosing Alias Violations In Memory Access Commands In Source Code,” incorporated herein for all purposes, all the symbol assignments and types are traced in a program. A diagnostic may be provided at the point of the symbol dereference that outlines why the symbol dereference may be dangerous and flags a symbol that may be pointing to a memory location with the wrong type. The tracing and diagnostic results may only be fully effective if the compiler can analyze all files and procedures that are part of the program.
However, in applications that include multiple program files or compilation units, it may not be possible to analyze the entire program because the compiler may not have access to all the program source code.